<template>
  <a-modal
    :visible="visible"
    title="归还"
    cancelText="取消"
    okText="归还"
    @ok="submit"
    @cancel="cancel"
  >


    <a-form
      ref="formRef"
      :model="formState"
      :rules="formRules"
      :label-col="labelCol"
      :wrapper-col="wrapperCol"
    >
      <a-form-item ref="goodsName" label="物品名称" name="goodsName">
        <a-input v-model:value="formState.goodsName" disabled="true" />
      </a-form-item>
      <a-form-item ref="applicationNumber" label="申请数量" name="applicationNumber">
        <a-input type="number" v-model:value="formState.applicationNumber"  disabled="true"/>
      </a-form-item>
      <a-form-item ref="applicationNumber" label="申请人" name="nickname">
        <a-input type="text" v-model:value="formState.nickname" disabled="true"  />
      </a-form-item>
      <a-form-item ref="application" label="申请用途" name="application">
        <a-input v-model:value="formState.application"  disabled="true"/>
      </a-form-item>
      <a-form-item label="申请时间" name="applicationTime">
        <a-input type="datetime" v-model:value="formState.applicationTime" disabled="true"/>
      </a-form-item>
      <a-form-item label="归还数量" name="returnNumber">
        <a-input type="number" v-model:value="formState.returnNumber" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
import {createVNode, defineComponent, reactive, ref, toRaw, watch} from "vue";
import {message, modal} from "_ant-design-vue@2.2.8@ant-design-vue";
import {applyRefuse, applyReturn} from "@/api/module/application";
export default defineComponent({
  props: {
    visible: {
      type: Boolean,
    },
    record: {
      type: Object,
    }
  },
  emit: ["close"],
  setup(props, context) {

    const formRef = ref();

    const formState = reactive({
      returnNumber:0
    });

    watch(props, (props) => {
      console.log("props++--++--",props.record)
      formState.id = props.record.id
      formState.nickname = props.record.nickname
      formState.danferousroomId = props.record.danferousroomId
      formState.goodsName = props.record.goodsName
      formState.application = props.record.application
      formState.applicationTime = props.record.applicationTime
      formState.applicationNumber = props.record.applicationNumber
    })

    const formRules = { };


    const submit = (e) => {
      applyReturn(toRaw(formState)).then((response) => {
        if(response.success){
          message.success({content: "归还成功", duration: 1})
          cancel();
        }else{
          message.error({content: response.msg, duration: 1})
          cancel();
        }
      })
    };


    const cancel = (e) => {
      formRef.value.resetFields();
      context.emit("close", false);
    };

    return {
      submit,
      cancel,
      formRef,
      formState,
      formRules,

      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
    };
  },
});
</script>
